package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.clue.*;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.ClueService;
import com.qk.vo.clue.CluePoolVO;
import com.qk.vo.clue.ClueQueryVO;
import com.qk.vo.clue.ClueVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author lyl
 * @created 2025/10/13 20:27
 * @description
 *
 */
@Slf4j
@RestController
@RequestMapping("/clues")
@SuppressWarnings("all")
public class ClueController {

    @Autowired
    private ClueService clueService;

    @GetMapping("/pool")
    public Result getCluePool(CluePoolDTO cluePoolDTO) {
        log.info("查询线索池");
        PageResult<CluePoolVO> pageResult = clueService.getCluePool(cluePoolDTO);
        return Result.success(pageResult);
    }

    @LogAnno
    @PutMapping("/false/{id}")
    public Result falseClue(@PathVariable Integer id, @RequestBody FalseClueDTO falseClueDTO) {
        log.info("伪线索处理：id={},原因数据={}", id,falseClueDTO.toString());
        clueService.falseClue(id, falseClueDTO);
        return Result.success();
    }

    @LogAnno
    @PutMapping("/toBusiness/{id}")
    public Result toBusiness(@PathVariable Integer id) {
        log.info("线索转商机：id={}", id);
        clueService.toBusiness(id);
        return Result.success();
    }

    @LogAnno
    @PutMapping
    public Result updateClue(@RequestBody UpdateClueInfoDTO updateClueInfoDTO) {
        log.info("跟进线索：clueDTO={}", updateClueInfoDTO.toString());
        clueService.updateClue(updateClueInfoDTO);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getClueInfoById(@PathVariable Integer id) {
        log.info("根据ID查询线索,线索ID={}", id);
        ClueVO clue = clueService.getClueInfoById(id);
        return Result.success(clue);
    }

    @LogAnno
    @PutMapping("/assign/{clueId}/{userId}")
    public Result assign(@PathVariable Integer clueId, @PathVariable Integer userId) {
        log.info("分配线索：clueId={},userId={}", clueId, userId);
        clueService.assign(clueId, userId);
        return Result.success();
    }

    @GetMapping
    public Result list(ClueQueryDTO clueDTO) {
        log.info("分页查询线索,参数:手机={},线索状态={},线索来源={},线索归属人={},当前页码={},每页大小={}", clueDTO.getPhone(), clueDTO.getStatus(), clueDTO.getChannel(), clueDTO.getAssignName(), clueDTO.getPage(), clueDTO.getPageSize());
        PageResult<ClueQueryVO> pageResult = clueService.getListPage(clueDTO);
        return Result.success(pageResult);
    }

    @LogAnno
    @PostMapping
    public Result addClue(@RequestBody ClueDTO clueDTO) {
        log.info("添加线索：clueDTO={}", clueDTO.toString());
        clueService.addClue(clueDTO);
        return Result.success();
    }

}
